<template>
  <div id="app">
    <div>
      <input v-model="message" placeholder="输入事项内容"/>
      <button v-on:click="addItem">添加</button>
    </div>
    <h1 v-for="(item, index) of list" :key="index">{{index+1}}:{{item.name}}</h1>
  </div>
</template>

<script>
import axios from 'axios'


export default {
  name: 'App',
  components: {
  },
  data () {
    return {
      list: [],
      message:""
    }
  },
  methods: {
    /* 第三步 写一个name事件  */
    addItem () {
      console.log(this.message)
      axios({
        method: 'post',
        url: 'http://localhost:28080/addTodo',
        params: {
          title: this.message
        }
      })
    },
    name () {
      axios({
        method: 'get',
        url: 'http://localhost:28080/getTodoList'
      }).then((res) => {
        this.list = res.data.data
      })
    }
  },
  /* 第四步 在create钩子函数中 将name事件在页面出现的时候执行 */
  created () {
    this.name()
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
